// pages/historiesData/historiesData.js
var utils = require('../../utils/util.js');
var httpUrl = getApp().globalData.httpUrl;
Page({
    data: {
        isdisabled: true,
        dayDate:""
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getHealth(this.data.dayDate);
    },
    getHealth:function(data){
        var that=this;
        utils.http(httpUrl + "/mobile/member/get_health_state", { date:data},function(res){
            // console.log(res)
            if (res.state == 1) {
                that.setData({
                    dataslist: res.datas.datas_list,
                    dayDate: res.datas.datas_list.date,
                    statelist: res.datas.state_list
                })
            }else{
                utils.message(res.datas)
            } 
        })
    },

    //选择日期
    bindDateChange: function(e) {
        var that=this;
        this.setData({
            dayDate: e.detail.value,
            isdisabled:true,
        })
        that.getHealth(that.data.dayDate);
    },

    //编辑记事本 状态改为false   isdisabled=false   
    formReset: function(e) {
        console.log(e);
        this.setData({
            isdisabled: false,
            isfocus:true
        })
    },
    //修改健康数据修改 
    oNnotepadTap:function(e){
        var that=this;
        that.setData({
            isdisabled: true,
        })
        utils.showLoading();
        var nameheight = e.detail.value.nameheight;
        var nameweight = e.detail.value.nameweight;
        var namehead = e.detail.value.namehead;
        var namebust = e.detail.value.namebust;
        var nametooth = e.detail.value.nametooth;
        var namevision = e.detail.value.namevision;
        var namehearing = e.detail.value.namehearing;
        if (nameheight != 0 && nameweight != 0 && namehead != 0 && namebust != 0 && nametooth != 0 && namevision != 0 && namehearing != 0) {
            utils.http(httpUrl + "/mobile/member/health_modify", {
                date: that.data.dayDate,
                id: e.detail.target.dataset.id,
                height: nameheight, //类型：Number  必有字段  备注：身高
                weight: nameweight, //类型：Number  必有字段  备注：日中
                head_cir: namehead, //类型：String  必有字段  备注：头围
                bust_cir: namebust, //类型：String  必有字段  备注：胸围
                tooth: nametooth, //类型：String  必有字段  备注：牙齿
                vision: namevision, //类型：String  必有字段  备注：视力
                hearing: namehearing, //类型：String  必有字段  备注：听力
            }, function (res) {
                if (res.state == 1) {
                    utils.hideLoading();
                    wx.showToast({
                        title: '保存成功',
                        duration: 2000
                    })
                    setTimeout(function(){
                        wx.navigateBack();
                    },2000);
                } else {
                    utils.message(res.datas);
                }
            })
        } else {
            if (nameheight == 0) {
                wx.showToast({
                    title: '请输入身高',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (nameweight == 0) {
                wx.showToast({
                    title: '请输入体重',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (namehead == 0) {
                wx.showToast({
                    title: '请输入头围',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (namebust == 0) {
                wx.showToast({
                    title: '请输入胸围',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (nametooth == 0) {
                wx.showToast({
                    title: '请输入牙齿',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (namevision == 0) {
                wx.showToast({
                    title: '请输入视力',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (namehearing == 0) {
                wx.showToast({
                    title: '请输入听力',
                    image: '/images/error.png',
                    duration: 2000
                })
            }

        }

    }
})